package com.jic.product.controller.manage;

import com.jic.common.base.vo.RestResult;
import com.jic.product.entity.ProductPrice;
import com.jic.product.manage.request.ProductBatchUpdateRequest;
import com.jic.product.manage.request.ProductPriceRequest;
import com.jic.product.manage.response.ProductPriceResponse;
import com.jic.product.service.ProductPriceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by WS on 2020/2/7  15: 19
 * 商品价格
 */
@RestController
@RequestMapping("/productPrice")
@Api(value = "商品价格", tags = {"商品价格"})
public class ProductPriceController {

    @Autowired
    ProductPriceService productPriceService;

    /*
     *  商品描述查询
     *
     * */
    @ApiOperation(value = "商品价格信息条件查询")
    @ResponseBody
    @PostMapping(value = "/queryProductPrice")
    public RestResult<ProductPriceResponse> query(@RequestBody ProductPriceRequest price) {
        ProductPriceResponse productPriceResponse = productPriceService.queryProductPrice(price);
        return RestResult.success(productPriceResponse);
    }

    /*
     *  商品价格信息修改
     *
     * */
    @ApiOperation(value = "商品价格信息修改")
    @ResponseBody
    @PostMapping(value = "/updateProductPrice")
    public RestResult updateProductPrice(ProductPrice productPrice) {
        RestResult restResult = new RestResult<>();

        try {
            long flag = productPriceService.update(productPrice);
            if (flag == 1) {
                restResult = RestResult.success(restResult);
            }
        } catch (Exception e) {
            e.printStackTrace();
            restResult = RestResult.error("9999", e.getLocalizedMessage());
        }
        return restResult;
    }


    /*
     *  批量商品价格信息修改
     *
     * */
    @ApiOperation(value = "批量商品价格信息修改")
    @ResponseBody
    @PostMapping(value = "/batchUpdateProductPrice")
    public RestResult batchUpdateProductPrice(@RequestBody ProductBatchUpdateRequest productBatchUpdateRequest) {
      return productPriceService.batchUpdateProductPrice(productBatchUpdateRequest);
    }

}
